<?php

	class Media_HttpProvider
	{
		var $rooturl;
		var $rootpath;
		var $folder;
		
		public function __construct($rootpath = '/',$rooturl = '/',$folder = '')
		{
			$this->rootpath = $rootpath;
			$this->rooturl 	= $rooturl;
			$this->folder	= $folder;
		}
						
		public function upload($source,$code)
		{
			if (!file_exists($this->rootpath.'/'.$this->folder))
			{
				$this->chmodr($this->rootpath,777);
				//echo "mkdir(".$this->rootpath.'/'.$this->folder.")";
				mkdir($this->rootpath.'/'.$this->folder,777,true);
			}

			return move_uploaded_file($source, $this->getFilePath($code));
		}
		
		static public function getCode($ext)
		{
			return eb_generate_code(5).'.'.$ext;
		}
		
		public function getFileUrl($code)
		{
			return $this->rooturl.$this->folder.$code;
		}		
		
		public function getFilePath($code)
		{
			return $this->rootpath.'/'.$this->folder.$code;
		}
	}